﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="UploadFile.ascx.cs" Inherits="Controls_UploadFile_UploadFile" %>
<%@ Register assembly="Krystalware.SlickUpload" namespace="Krystalware.SlickUpload.Controls" tagprefix="kw" %>

<asp:Panel ID="Panel1" runat="server" Style="display: none;" CssClass="modalPopup" Width="400px">
    <asp:Panel ID="Panel2" runat="server" CssClass="modalPopupHeader">
        <div>&nbsp;&nbsp;&nbsp;<asp:Literal ID="literalModalPopup" runat="server"></asp:Literal></div>
    </asp:Panel>
        <div style="padding:2px; height:215px;">
            <kw:slickupload ID="slickUpload" runat="server" 
                OnClientUploadEnded="modalPopupHide" 
                OnUploadComplete="slickUpload_UploadComplete"      
                >
                <filetemplate>
                    <div style="border:solid 1px #ccc;margin:3px;padding:5px">
                        <kw:FileListRemoveLink ID="FileListRemoveLink1" runat="server" Title="Remove" style="float:right;">                    
                            <div class="uploadCancel">删除</div>                 
                        </kw:FileListRemoveLink>                
                        <div class="uploadFile">
                        <kw:FileListFileName ID="FileListFileName1" runat="server" style="font-size:22px" />&nbsp;
                        <kw:FileListValidationMessage ID="FileListValidationMessage1" runat="server" style="font-size:12px; color:Red;"/>
                        </div>
                    </div>
                </filetemplate>
                <progresstemplate>
                    <div class="uploadInfo">
                        上传文件:                                                
                        第<kw:uploadprogresselement ID="Uploadprogresselement1" runat="server" Element="CurrentFileIndex">
                            </kw:uploadprogresselement>个/共<kw:uploadprogresselement ID="Uploadprogresselement2" runat="server" Element="FileCount">
                        </kw:uploadprogresselement>个,
                        <kw:uploadprogresselement ID="Uploadprogresselement3" runat="server" Element="ContentLengthText">
                            ...</kw:uploadprogresselement><br />
            
                        当前上传:
                        <kw:uploadprogresselement ID="Uploadprogresselement4" runat="server" Element="CurrentFileName">
                        </kw:uploadprogresselement>       <br />                  
            
                        上传速度:
                        <kw:uploadprogresselement ID="Uploadprogresselement5" runat="server" Element="SpeedText">
                            ...</kw:uploadprogresselement><br />
            
                        剩余时间:
                        <kw:uploadprogresselement ID="Uploadprogresselement6" runat="server" Element="TimeRemainingText">
                            ...</kw:uploadprogresselement>                        
                    </div>
                    <div style="border:1px solid #999;height:6px;position:relative; font-size:10px; margin:10px 20px">
                        <kw:uploadprogressbarelement ID="Uploadprogressbarelement1" runat="server" 
                            style="background-color:#32b0ff;width:0px;height:8px">
                        </kw:uploadprogressbarelement>
                        <div style="text-align:center;position:absolute; top:-1px; width:100%; font-family:Verdana, Sans-Serif">
                                <kw:uploadprogresselement ID="Uploadprogresselement7" runat="server" Element="PercentCompleteText">
                                    ...</kw:uploadprogresselement>
                        </div>
                    </div>
                </progresstemplate>
                <selectorhtmltemplate>
                    <input type="file" />
                </selectorhtmltemplate>
            </kw:slickupload> 
        </div>
        <div class="modalPopupFooter">
             <asp:CheckBox ID="cbInsertEditer" Text="上传后插入编辑器"  runat="server" Checked="true"
                 style="float:left;"/>
             <a id="btnModalPopupOK" href="#" 
                onclick="uploadFile();" >确定</a>
             <a id="btnModalPopupCancel" href="#" 
                onclick="return false;" >取消</a>
             <p style="display:none"><ofcc:LinkButton ID="btnModalPopupNone" 
                runat="server" >None Event</ofcc:LinkButton></p>
        </div>
</asp:Panel>
<ajax:ModalPopupExtender runat="server" ID="modalPopup"    
    PopupControlID="Panel1" 
    PopupDragHandleControlID="Panel2"
    TargetControlID="btnModalPopupNone"
    BackgroundCssClass="modalBackground"
    BehaviorID="modalPopupBehavior" 
    DropShadow="True"
    >    
</ajax:ModalPopupExtender>
<script type="text/javascript">
    function pageLoad() {
        $addHandler($get('<%=ViewState["ShowButtonClientID"].ToString() %>'), 'click', modalPopupShow);
        $addHandler($get("btnModalPopupCancel"), 'click', modalPopupHide);
    }

    function modalPopupShow(ev) {
        ev.preventDefault();
        var modalPopupBehavior = $find('modalPopupBehavior');
        modalPopupBehavior.show();
    }

    function modalPopupHide(ev) {
        //fix firefox
        if ($get('<%=Panel1.ClientID %>') != null)
            $get('<%=Panel1.ClientID %>').style.display = "none";

        if ($get('<%=Panel1.ClientID %>_DropShadow') != null)
            $get('<%=Panel1.ClientID %>_DropShadow').style.display = "none";

        if ($get('<%=Panel1.ClientID %>__progressDisplay') != null)
            $get('<%=Panel1.ClientID %>__progressDisplay').style.display = "none";

        var divList = $$('div.modalBackground');
        divList[0].style.display = "none";
        
        if (ev.type == "click") ev.preventDefault();        
        var modalPopupBehavior = $find('modalPopupBehavior');
        modalPopupBehavior.hide();
    }

    function uploadFile() {
        if (kw.get("<%=slickUpload.ClientID %>").get_Files().length > 0) {
            //submit(false); false 可以避免表单验证
            kw.get('<%=slickUpload.ClientID %>').submit(false);
        }
    }

    //fix ScriptManager and slickUpload 同时存在  LinkButton and AutoPostBack 不提交的问题
    window.__doPostBack = Function.createDelegate(this, this._doPostBack);
    function _doPostBack(eventTarget, eventArgument) {
        var errormessage = "";
        for (i = 0; i < Page_Validators.length; i++) {
            if (!Page_Validators[i].isvalid && typeof (Page_Validators[i].errormessage) == "string") {
                errormessage += Page_Validators[i].errormessage;
            }
        }
        if (errormessage != "") return;
        
        if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
            theForm.__EVENTTARGET.value = eventTarget;
            theForm.__EVENTARGUMENT.value = eventArgument;
            theForm.submit();
        }
    }
</script>
    